package fileinputstream;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : FileInputStreamDemo1
 * @Author : 54061
 * @Date: 2022/2/14 9:05
 */
/*
    输入流指向的文件必须存在!!

 */
public class FileInputStreamDemo1 {
    public static void main(String[] args) throws IOException {
        //创建对象
        FileInputStream fis = new FileInputStream("T_Day17\\aaa\\FileOutputStreamDemo1.java");


        //一次读一个字节的标准代码
        //定义一个int类型的变量名字 : by
        int by;
        //循环读
        /*
            1: fis.read() 一次读一个字节
            2: by = fis.read() : 把读到的字节赋值给by
            3. by != -1 : 若不是-1 说明读到了数据
         */
        while ((by = fis.read()) != -1) {
            //输出: 需要把int 转成 char  且不要换行
            System.out.print((char) by);
        }


        //关闭资源
        fis.close();
    }

    public static void method(FileInputStream fis) throws IOException {
        //一次读一个字节
        int by = fis.read();
        System.out.println("by = " + (char) by);//a
        by = fis.read();
        System.out.println("by = " + (char) by);//b
        by = fis.read();
        System.out.println("by = " + (char) by);//c

        System.out.println(fis.read());
        System.out.println(fis.read());
        System.out.println(fis.read());
        System.out.println(fis.read());
        System.out.println(fis.read());
        System.out.println(fis.read());
    }
}
